﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessConsumerAccount
// 文件功能描述：消费账号维护数据访问层
//
// 
// 创建标识：2012-06-15 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessConsumerAccount
    {
        /// <summary>
        /// 获取账号信息
        /// </summary>
        /// <returns></returns>
        public DataSet GetList(int pagesize, int startindex)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY userid ASC) rownumber,* " +
                               "from rightuser) B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 获取账号数量
        /// </summary>
        /// <returns></returns>
        public int GetListCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from rightuser";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 删除账号
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteConsumerAccount(string id)
        {
            sqldb db = new sqldb();
            string query = "Delete from rightuser where userid in(" + id + ")";
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }

        /// <summary>
        /// 保存账号(新增界面下)
        /// </summary>
        /// <param name="supp"></param>
        /// <returns></returns>
        public int SaveConsumerAccount(object[] yax)
        {
            sqldb db = new sqldb();
            string query = "insert into rightuser(dispname,groupid,passwords) Values('" +
                yax[0] + "','" + "4','" + yax[1] + "')";
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }

        /// <summary>
        /// 保存账号(修改界面下)
        /// </summary>
        /// <param name="supp"></param>
        /// <returns></returns>
        public int SaveConsumerAccountEdit(object[] supp)
        {
            sqldb db = new sqldb();
            string query = "update rightuser set dispname='" + supp[1] + "',passwords='" + supp[2] + "' where userid=" + supp[0];
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }

        /// <summary>
        /// 根据编号获取一条账号信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public DataSet GetConsumerAccountInfoOne(string id)
        {
            sqldb db = new sqldb();
            string query = "select * from rightuser where userid = '" + id + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }
    }
}
